﻿using MeetSomeNearbyStrangerWebApi.ConfigurationSettings;
using MeetSomeNearbyStrangerWebApi.MessageHandlers;
using System;
using System.Linq;
using System.Web.Http;

namespace MeetSomeNearbyStrangerWebApi
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MessageHandlers.Add(new BasicMessageHandler());

            string usersController = "users";
            ControllerManager.RegisterController(usersController);
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.SendUserData, Type = HttpMethod.POST });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.SetGCMRegID, Type = HttpMethod.POST });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.GetMyProfile, Type = HttpMethod.GET });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.GetProfile, Type = HttpMethod.GET });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.UploadImage, Type = HttpMethod.POST });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.GetMyInterests, Type = HttpMethod.GET });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.GetOtherInterests, Type = HttpMethod.GET });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.SendLocation, Type = HttpMethod.PUT });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.AddInterest, Type = HttpMethod.PUT });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.GetUsersMediumView, Type = HttpMethod.GET });
            ControllerManager.RegisterAction(usersController, new ControllerAction() { Name = UsersControllerActions.GetUsersOnVisibleMap, Type = HttpMethod.GET });

            config.Routes.MapHttpRoute(
                name: "UsersApi",
                routeTemplate: "api/users/{action}",
                defaults: new
                {
                    controller = "users"
                }
            );

            config.Routes.MapHttpRoute(
                name: "MeetsApi",
                routeTemplate: "api/meets/{action}",
                defaults: new
                {
                    controller = "meets"
                }
            );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();
        }
    }
}
